layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    var catId = $("#catId").val();
    //列表
    var tableIns = table.render({
        elem: '#entityList',
        url : '/receiving/jsonCurrentList',
        where: {type:2},
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 20,
        method:'post',
        limits : [10,15,20,25],
        id : "entityList",
        cols : [[
            {type: 'numbers', title: '序号'},
            {field: 'activityTitle',minWidth:120, title: '活动名称',align:'center'},
            {field: 'itemTitle',minWidth:120, title: '商品名称',align:'center'},
            {field: 'otherUserName',minWidth:120, title: '转让人',align:'center'},
            {field: 'transferPrice',minWidth:120, title: '转让钻石',align:'center'},
            {field: 'winningNum',minWidth:120, title: '中奖号',align:'center'},
            {field: 'status', title: '状态',align:'center',width:100,templet:function(d){
                if(d.status=="1"){
                    return "未收货";
                }else if(d.status=="2"){
                    return "已收货";
                }
            }},
            {field: 'createTime',minWidth:170, title: '创建时间', align:'center', templet:function(d){
                return d.createTime;
            }},
            {title: '操作',width:170,align:"center", templet:function(d){
                return '<a class="layui-btn layui-btn-xs" lay-event="show">编辑</a>';
            }}
        ]]
    });

    //搜索
    $(".search_btn").on("click",function(){
        table.reload("entityList",{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                otherUserName: $("#otherUserName").val()
            }
        })
    });

    //增加/编辑
    function addEntity(params){
        var title="编辑";
        var index = layui.layer.open({
            title :title,
            type : 2,
            content : "/receiving/selectPersonalEntity"+params,
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                body.find(".closeLay").bind("click",function () {
                    layui.layer.close(index);
                })
                layui.layer.full(index);
            }
        });
    }
    $(".add_btn").click(function(){
        addEntity('');
    })

    //列表操作
    table.on('tool(entityList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
        if(layEvent === 'show'){ //编辑
            addEntity("?id="+data.id);
        }
    });

})